
package com.phm.phmneuron.neuron;

import java.util.HashSet;
import java.util.List;
import java.util.Objects;

/**
 *
 * @author PARHAM
 */
public class NeuronsContainer {
    protected HashSet<Neuron> _neurons = new HashSet<>();
    
    public NeuronsContainer () {
        // Empty body
    }
    public NeuronsContainer (List<Neuron> neurons) {
        _neurons.addAll(neurons);
    }
    
    public boolean addNeuron (Neuron n) {
        return _neurons.add(Objects.requireNonNull(n));
    }
    public boolean updateNeuron (Neuron n) {
        if (n == null) return false;
        if (!_neurons.add(n)) {
            _neurons.remove(n);
            _neurons.add(n);
        } 
        return true;
    }
    public boolean removeNeuron (Neuron n) {
        return _neurons.remove(n);
    }
    public void clearNeurons () {
        _neurons.clear();
    }
    public Neuron getNeuron (String id) {
        Neuron n = null;
        for (Neuron x : _neurons) {
            if (x.id.equals(id)) {
                return x;
            }
        }
        return null;
    }
    public Neuron [] getNeurons (){
        return _neurons.toArray(new Neuron [0]);
    }
    public int countNeurons () {
        return _neurons.size();
    }
}
